//
//  EDSPublishDynamicImageView.m
//  DriveSchoolCoach
//
//  Created by TangBin on 2019/7/31.
//  Copyright © 2019 TangBin. All rights reserved.
//

#import "EDSPublishDynamicImageView.h"

@interface EDSPublishDynamicImageView ()
@property (nonatomic, strong) UIButton *btnDelete;

/// 播放
@property (nonatomic, strong) UIButton *btnPlayVideo;

- (void)initWithBtnDelete;

@end

@implementation EDSPublishDynamicImageView

// btn_communtiy_dynamic_del_small

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.userInteractionEnabled = YES;
        [self initWithBtnDelete];
        
        [self initWithBtnPlayVideo];
    }
    return self;
}

- (void)initWithBtnDelete
{
    
    CGRect frame = CGRectMake(self.width-20, 0, 20, 20);
    _btnDelete = [UIButton buttonWithType:UIButtonTypeCustom];
    _btnDelete.frame = frame;
    [_btnDelete setImage:[UIImage imageNamed:@"btn_communtiy_dynamic_del_small"] forState:UIControlStateNormal];
    [_btnDelete addTarget:self action:@selector(clickedDelete:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnDelete];
}

- (void)initWithBtnPlayVideo {
    UIImage *image = [UIImage imageNamed:@"com_play_big_ic"];
    CGRect frame = CGRectMake((self.width - image.size.width) * 0.5, (self.height - image.size.height) * 0.5, image.size.width, image.size.height);
    _btnPlayVideo = [UIButton createWithButton:self frame:frame font:FONTSIZE(16) target:self action:@selector(clickedPlay:) propertiesBlock:^(UIButton * _Nonnull button) {
        [button setImage:image forState:UIControlStateNormal];
        button.hidden = YES;
    }];
}

- (void)setShowPlayBtn:(BOOL)showPlayBtn {
    _btnPlayVideo.hidden = !showPlayBtn;
    [self bringSubviewToFront:_btnPlayVideo];
}

/// 播放
/// - Parameter sender: sender description
- (void)clickedPlay:(id)sender {
    if (self.touchPlayVideoBlock) {
        self.touchPlayVideoBlock(self.tag);
    }
}

- (void)clickedDelete:(id)sender
{
    if (self.deleteImageBlock)
    {
        self.deleteImageBlock(self.tag);
    }
}

@end
